package com.siwei.mes.common.util;

import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;

/**
 * @author: mlchen
 * @createDate: 2023/1/12
 * @description: 单位装换
 */
public class UtilHelper {
    /**
     * 千克转吨  / 克转千克
     *
     * @return
     */
    public static Double kgForTon(Object str) {
        double number = 0.0;
        if (ObjectUtils.isEmpty(str)) {
            return number;
        }
        number = Double.parseDouble(String.valueOf(str)) / 1000;
        return number;
    }

    public static Double checkNumber(Double str, Integer scale) {
        if (str == null) {
            return (double) 0;
        }
        BigDecimal bigDecimal = new BigDecimal(str).setScale(scale, BigDecimal.ROUND_HALF_UP);
        return bigDecimal.doubleValue();
    }


    public static void main(String[] args) {
        System.out.println(kgForTon(1000));
    }
}
